<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.*,hotel.entity.*" %>
<%@include file="../link.html"%>
<script type="text/javascript">
$(document).ready(function() {
	$("#btn-close").click( function () { 
		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭 
	});
});

layui.use('laydate', function(){
	var start = layui.laydate;
	//执行一个laydate实例
	start.render({
		elem: '#start_time', //指定元素
		value: new Date()
	});
	var end = layui.laydate;
	//执行一个laydate实例
	end.render({
		elem: '#end_time' //指定元素
	});
});

function addPrice(){
	var index=$('#btn-submit').attr('class').indexOf("disabled");
	if(index==-1){//disabled的下标为-1说明确定按钮可用
		$.ajax({
	        type:"post",
	        url:"addPrice",
	        data: $('#priceForm').serialize(),//表单数据
	        success: function(data){
				layer.msg('创建成功', {icon: 1, time: 800}, function(){//关闭后执行的操作
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭 
					});  
	        }
	    });
	}
	return false;
}
</script>

<div style="padding-top:35px;">
	<form id="priceForm" action="addPrice" method="post" class="form-horizontal" 
	data-toggle="validator" role="form">
		<div class="form-group">
			<label class="col-sm-4 control-label">所属房型</label>
			<div class="col-sm-5">
				<select id="select" name="category.categoryid" class="form-control">
					<%
					List<Category> list=(List<Category>)request.getAttribute("categoryList");
					if(list!=null&&list.size()>0)
					for(Category c:list){
						out.print("<option value='"+c.getCategoryid()+"'>"+c.getCategoryName()+"</option>");
					}
					%>
				</select>
			</div>
			<div class="help-block with-errors"></div>
		</div>

		<div class="form-group">
			<label class="col-sm-4 control-label">开始时间</label>
			<div class="col-sm-5">
				<div class="input-group date">
					<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
					<input id="start_time" name="start_time" class="form-control" required>
				</div>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label">结束时间</label>
			<div class="col-sm-5">
				<div class="input-group date">
					<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
					<input id="end_time" name="end_time" class="form-control">
				</div>
			</div>
		</div>

		<div class="form-group">
			<label class="col-sm-4 control-label">价格</label>
			<div class="col-sm-5">
				<input name="price" class="form-control" type="number" min="1" value="1" required>
			</div>
		</div>
		
		<div class="form-group">
			<label class="col-sm-4 control-label"></label>
			<div class="col-sm-5">
				<button id="btn-close" class="btn btn-close btn-primary" type="button">关闭</button>
				<div class="pull-right">
					<button id="btn-submit" type="submit" class="btn btn-primary" onClick="return addPrice()">确定</button>
				</div>
			</div>
		</div>
	</form>
</div>